package com.caine.common.tool;

import com.caine.common.entity.R;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@Slf4j
public class PrintTool {
    /**
     * 返回信息输出
     *
     * @param response
     * @param r
     */
    public static void printMsg(HttpServletResponse response, R r) {
        response.setContentType("application/json;charset=utf-8");
        PrintWriter out = null;
        try {
            out = response.getWriter();
            out.write(JSONTool.toString(r));
            out.flush();
            out.close();
        } catch (IOException e) {
            log.error("访问受限返回输出异常", e);
        }
    }
}
